package com.test.enumtest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 3.症状
 */
public enum EnumSGA3 {

    // 1.过去二个星期，患者有下列的问题困扰，使其无法吃的足够
    ANSWER1_1(1, 0, "没有饮食方面的问题"),
    ANSWER1_2(2, 3, "没有食欲，就是不想吃"),
    ANSWER1_4(4, 1, "口干"),
    ANSWER1_8(8, 1, "恶心"),
    ANSWER1_16(16, 3, "呕吐"),
    ANSWER1_32(32, 1, "便秘"),
    ANSWER1_64(64, 3, "腹泻"),
    ANSWER1_128(128, 2, "口痛"),
    ANSWER1_256(256, 1, "容易饱胀"),
    ANSWER1_512(512, 2, "吞咽困难"),
    ANSWER1_1024(1024, 1, "吃起来感觉没有味道，或味道变得奇怪"),
    ANSWER1_2048(2048, 2, "有怪味困扰着我"),
    ANSWER1_4096(4096, 3, "疼痛"),
    ANSWER1_8192(8192, 1, "其他"),

    ;

    public final int id;
    public final int score;
    public final String name;

    EnumSGA3(int id, int score, String name) {
        this.id = id;
        this.score = score;
        this.name = name;
    }

    /**
     * 获取答案列表 1.过去二个星期，患者有下列的问题困扰，使其无法吃的足够
     *
     * @return
     */
    public static List<Map<String, Object>> getAnswerList() {
        List<Map<String, Object>> list = new ArrayList<>();
        list.add(createMap(1));
        list.add(createMap(2));
        list.add(createMap(4));
        list.add(createMap(8));
        list.add(createMap(16));
        list.add(createMap(32));
        list.add(createMap(64));
        list.add(createMap(128));
        list.add(createMap(256));
        list.add(createMap(512));
        list.add(createMap(1024));
        list.add(createMap(2048));
        list.add(createMap(4096));
        list.add(createMap(8192));
        return list;
    }

    /**
     * 根据id获取枚举
     *
     * @param id
     * @return
     */
    public static EnumSGA3 get(int id) {
        switch (id) {
            case 1:
                return ANSWER1_1;
            case 2:
                return ANSWER1_2;
            case 4:
                return ANSWER1_4;
            case 8:
                return ANSWER1_8;
            case 16:
                return ANSWER1_16;
            case 32:
                return ANSWER1_32;
            case 64:
                return ANSWER1_64;
            case 128:
                return ANSWER1_128;
            case 256:
                return ANSWER1_256;
            case 512:
                return ANSWER1_512;
            case 1024:
                return ANSWER1_1024;
            case 2048:
                return ANSWER1_2048;
            case 4096:
                return ANSWER1_4096;
            case 8192:
                return ANSWER1_8192;
            default:
                return null;
        }
    }

    /**
     * 根据id获取分数
     *
     * @param id
     * @return
     */
    public static int getScore(int id) {
        EnumSGA3 en = EnumSGA3.get(id);
        if (en != null) {
            return en.score;
        } else {
            return -1;
        }
    }

    private static Map<String, Object> createMap(int id) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", EnumSGA3.get(id).id);
        map.put("name", EnumSGA3.get(id).name);
        map.put("score", EnumSGA3.get(id).score);
        return map;
    }
}
